from pytz import timezone
from datetime import datetime
from django.utils.timezone import make_aware
from django.conf import settings
import re


"""Parses a date-like input string into a timezone aware Python
datetime.
"""


def str_to_datetime(date_str, dt_format="%Y-%m-%d %H:%M:%S.%f"):
    regex = r'\+\d{2}:\d{2}'
    date_str = re.sub(regex,'',date_str.replace('T',' '))
    parsed = datetime.strptime(date_str, dt_format)
    return parsed.replace(tzinfo=timezone(settings.TIME_ZONE))



# print(str_to_datetime('2020-05-30T17:22:24.005571+08:00'))